#include "../head.h"
#include "../smartPtr/smartPtr.h"
template <typename T>
class complex
{
public:
    complex(T a, T b) : re(a), im(b) {}

    complex &operator+=(complex &obj)
    {
        re += obj.re;
        im += obj.im;
        return *this;
    }

    complex operator+(complex &obj2) const
    {
        return complex(real()+obj2.real(), imag()+obj2.imag());
    }

    T real() const {return re;}

    T imag() const {return im;}

    void display()
    {
        cout << re << "+" << im << "i" << endl;
    }
private:
    T re;
    T im;
};
// 把输入输出运算符在类外重载为了实现符合使用习惯的 cout << xxx, 如果在类内重载，则需要写成xxx << cout;
template<typename T>
ostream &
operator <<(ostream &os, const complex<T> &obj)
{
    return os << obj.real() << '+' << obj.imag() << 'i' << endl;
}

int main()
{
    smartPtr<complex<int> > obj1(new complex<int>(1, 2));
    complex<int> obj2(4, 5);
    obj2 += *obj1;
    obj2.display();

    complex<int> obj3 = obj2 + *obj1;
    obj3.display();
    cout << obj3;
    cout << "size of complex obj is " << sizeof(obj3) << endl;
}